package com.itheima.demo07;

import java.util.concurrent.Semaphore;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/14 16:50
 */
public class MyRunnable implements Runnable {
    Semaphore s = new Semaphore(2);

    @Override
    public void run() {
        //获取对象;
        try {
            s.acquire();
            System.out.println("拿到通行证开始行使");
            Thread.sleep(1000);
            System.out.println("归还通行证!");
            s.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
